<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        canvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<canvas width="600" height="600" id="can">您的浏览器不支持画布</canvas>
<script type="text/javascript">
    var can=document.getElementById("can");
    var pen=can.getContext("2d");
    //画画之前先清除一下画布，然后在开始作画
    pen.clearRect(0,0,can.width,can.height);

    //画一个矩形，给这个矩形在渲染之前添加上样式即可
    pen.beginPath();
    pen.rect(100,100,300,400);
    pen.strokeStyle="blue";
    pen.lineWidth="10";
    pen.fillStyle="red";
    pen.fill();
    pen.clearRect(100,100,300,400);
    pen.closePath();
    pen.stroke();
    pen.clearRect(0,0,can.width,can.height);

    pen.beginPath();
    pen.rect(450,450,100,100);
    //fillStyle重新设置的样式把之前的样式覆盖掉了
    pen.fillStyle="yellow";
    pen.fill();
    //strokeStyle改变了原来的样式
    pen.strokeStyle="green";
    pen.closePath();
    pen.stroke();
/////////////////////////////////////////////////




</script>
</body>
</html>